<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Topic extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	    $this->load->model('topic_model'); 
	}

	function index()
	{ 
		$data=$this->_page();
		$data['base_url']=base_url();
		$data['web_title']="主题";
	    $this->smarty->view("topic/index", $data); 
	}
	

	function detail($id=0)
	{ 
	    $topic=$this->topic_model->get_item('topicid',$id);
		if(count($topic)==1){
	    $data['topic'] = $topic[0];
		$data['base_url']=base_url();
		$data['web_title']=$topic[0]->subject."主题";
	    $this->smarty->view("topic/detail", $data); 
	    }else{
	    $this->smarty->view("common/404", $data); 
	    }
	}
	
	function page($page=0)
	{ 
		$data=$this->_page($page);
		$data['base_url']=base_url();
		$data['web_title']="主题 ";
	    $this->smarty->view("topic/index", $data); 
	}
	function _page($page=0)
	{ 
	    $this->load->library('pagination'); 
	    $this->load->helper('pageconfig');
	    $base_url = base_url().'index.php/topic/page/'; 
	    $total_rows = $this->topic_model->get_all_count();
	    $config=page_config($base_url,$total_rows);
	    $this->pagination->initialize($config);
	    unset($data); 
	    $results=$this->topic_model->get_items($config['per_page'],$page,'dateline','desc');
	    $data['topics'] = $results;
	    $data['pagination']=$this->pagination->create_links();
	    return $data;
	}
	
}
 